import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
//导入阿里字体
import './assets/fonts/iconfont.css'
// 导入全局样式表
import './assets/css/global.css'
import { Message, Loading } from 'element-ui'
import axios from 'axios'
import ZkTable from 'vue-table-with-tree-grid'
//配置请求的根路径
axios.defaults.baseURL = 'http://47.113.113.50:129/'
axios.interceptors.request.use(config => {
    Loading.service({ text: "Loading..." });
    config.headers.Authorization = 'Bearer ' + window.sessionStorage.getItem('token');
    return config;
}, err => {
    Message.error({ message: '请求超时!' });
    return Promise.resolve(err);
})

//  响应拦截
axios.interceptors.response.use(res => {
    Loading.service().close();

    if (res.data.errno === 501) {
        router.push('/login')
        return;
    } else if (res.data.errno === 403) {
        return Message.error('权限不足,请联系管理员!');
    }
    return res;
}, err => {
    Loading.service().close();
    if (err.response.status == 504 || err.response.status == 404) {
        Message.error('服务器被吃了⊙﹏⊙∥');
    } else {
        Message.error('未知错误');
    }
    return Promise.reject(err)
})
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.component('tree-table', ZkTable)
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
